CNF-26103: Add default case in istiocsr getIssuer to prevent nil-pointer - #463
CNF-26103: Add default case in istiocsr getIssuer to prevent nil-pointer#463sebrandon1 wants to merge 1 commit into
Conversation
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@sebrandon1: This pull request references CNF-26103 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
ChangesIssuer kind validation
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sebrandon1 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/controller/istiocsr/deployments.go (1)
499-500: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a focused test for the new default branch.
The existing invalid-kind reconciliation test fails earlier in
assertIssuerRefExists(lines 238-240), so it does not executegetIssuer’s new error path. Add a directgetIssuertest asserting the returned error and nil object.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/controller/istiocsr/deployments.go` around lines 499 - 500, Add a focused unit test for getIssuer that supplies an unsupported issuerRefKind and verifies it returns a nil issuer object plus the expected “unsupported issuer kind” error, bypassing assertIssuerRefExists so the default branch is exercised directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/controller/istiocsr/deployments.go`:
- Around line 499-500: Add a focused unit test for getIssuer that supplies an
unsupported issuerRefKind and verifies it returns a nil issuer object plus the
expected “unsupported issuer kind” error, bypassing assertIssuerRefExists so the
default branch is exercised directly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 707c2ef0-8710-4873-b407-40bd0a74bd2b
📒 Files selected for processing (1)
pkg/controller/istiocsr/deployments.go
864c7cf to
23b282d
Compare
07758cd to
5a40540
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/controller/istiocsr/deployments_test.go (1)
1341-1369: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the concrete object type for each supported kind.
The test only checks that
objis non-nil. It would pass if bothIssuerandClusterIssuerreturned the same object type. Add an expected type to each table entry and assert it aftergetIssuer.Proposed test adjustment
tests := []struct { - name string - kind string + name string + kind string + expectedType client.Object }{ - {name: "issuer kind", kind: "Issuer"}, - {name: "cluster issuer kind", kind: "ClusterIssuer"}, + {name: "issuer kind", kind: "Issuer", expectedType: &certmanagerv1.Issuer{}}, + {name: "cluster issuer kind", kind: "ClusterIssuer", expectedType: &certmanagerv1.ClusterIssuer{}}, }Then compare
reflect.TypeOf(obj)withreflect.TypeOf(tt.expectedType).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/controller/istiocsr/deployments_test.go` around lines 1341 - 1369, Update TestGetIssuerValidKinds by adding an expected concrete object type to each test case, using the Issuer type for “Issuer” and ClusterIssuer for “ClusterIssuer”. After getIssuer returns, compare the returned object’s type with the table entry’s expected type via reflect.TypeOf, replacing the insufficient nil-only assertion while preserving the existing error checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/controller/istiocsr/deployments_test.go`:
- Around line 1341-1369: Update TestGetIssuerValidKinds by adding an expected
concrete object type to each test case, using the Issuer type for “Issuer” and
ClusterIssuer for “ClusterIssuer”. After getIssuer returns, compare the returned
object’s type with the table entry’s expected type via reflect.TypeOf, replacing
the insufficient nil-only assertion while preserving the existing error checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b489cd24-d8c1-427d-b2b2-28237bc71eae
📒 Files selected for processing (1)
pkg/controller/istiocsr/deployments_test.go
Add a default case to the getIssuer switch that returns a descriptive error for unsupported issuer kinds instead of falling through with a nil object. Includes table-driven tests for all three branches (Issuer, ClusterIssuer, unsupported kind) with type assertions on the returned objects.
5c1fc74 to
c45bf2d
Compare
|
/retest |
|
@sebrandon1: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Summary
defaultcase to thegetIssuerswitch statement that returns a descriptive error instead of leavingobjectas nilr.Get()callassertIssuerRefExistsvalidating the kind first, but the function itself was unsafe for direct callersRelated PRs
Jira
Test Plan